package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.ClubDetailActivity;
import com.example.administrator.yuejian_2.bean.ClubListBean;
import com.example.administrator.yuejian_2.viewholder.ClubListViewHolder;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/29.
 */

public class ClubPopularListAdapter extends Adapter {


    private List<ClubListBean> club = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;
//    private FragmentManager manager;
//    private FragmentTransaction ft;

    public ClubPopularListAdapter(Context context, List<ClubListBean> club){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.club.addAll(club);

    }




    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_club,parent,false);
        ClubListViewHolder holder = new ClubListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ClubListViewHolder clubholder = (ClubListViewHolder) holder;
        ClubListBean clubpopularList = club.get(position);
        final String club_name = clubpopularList.getClub_name();
        clubholder.clubname.setText(club_name);
        String club_picture = clubpopularList.getClub_picture();
        if (!club_picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+club_picture)
                    .into(clubholder.clubpicture);

        final int club_id = clubpopularList.getClub_id();
        clubholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, ClubDetailActivity.class);
                intent.putExtra("club_id",club_id);
                intent.putExtra("club_name",club_name);
                context.startActivity(intent);

            }
        });


    }

    @Override
    public int getItemCount() {
        return club.size();
    }
}
